分类
联系方式
  1. 新浪微博
  2. E-mail

VirtualBox 挂载物理硬盘

介绍

VirtualBox 常规用法是在文件系统中创建一个文件,作为虚拟机的磁盘。而本文中的做法,是直接将物理硬盘挂载到虚拟机上。这样做的好处,是硬盘上的 GNU/Linux 的系统,可以脱离虚拟机,电脑冷启动直接进入。

本文主要介绍 Windows 下的设置方法,Linux 下可以参考网络资源中前人的经验。

Windows 设置方法

将 VirtualBox 安装目录添加到 PATH

否则命令行会提示找不到命令。

寻找硬盘设备号

命令行启动 diskpart 工具,输入 list disk

DISKPART> list disk

  磁盘 ###  状态           大小     可用     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  磁盘 0    联机              476 GB      0 B        *
  磁盘 1    联机              953 GB   760 MB

其中,磁盘1 是我想要挂载的物理硬盘。

磁盘映射命令

VBoxManage internalcommands createrawvmdk -filename D:\ssd-gentoo.vmdk -rawdisk \\.\PhysicalDrive1

其中:

  • D:\ssd-gentoo.vmdk:映射磁盘文件的名称
  • \\.\PhysicalDrive1:挂载的物理磁盘

遇到报错

报错如下:

PS C:\Users\maxie> VBoxManage internalcommands createrawvmdk -filename D:\ssd-gentoo.vmdk -rawdisk \\.\PhysicalDrive1

The 'createrawvdk' subcommand is deprecated.  The equivalent functionality is
available using the 'VBoxManage createmedium' command and should be used
instead.  See 'VBoxManage help createmedium' for details.

0%...VBOX_E_FILE_ERROR
VBoxManage.exe: error: Failed to create medium
VBoxManage.exe: error: Could not create the medium storage unit 'D:\ssd-gentoo.vmdk'.
VBoxManage.exe: error: VMDK: Image path: 'D:\ssd-gentoo.vmdk'. Failed to open the raw drive '\\.\PhysicalDrive1' for reading (VERR_ACCESS_DENIED) (VERR_ACCESS_DENIED).
VBoxManage.exe: error: VMDK: could not create raw descriptor for 'D:\ssd-gentoo.vmdk' (VERR_ACCESS_DENIED)
VBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium
VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreateMedium(struct HandlerArg *)" at line 634 of file VBoxManageDisk.cpp

解决方法:使用管理员权限运行上面命令。

createmedium

查看帮助 VBoxManage help createmedium

createmedium 命令用于创建新的媒介,比如磁盘映像文件。为了兼容老版本 VirtualBox,你也可以使用 createvdi 和 createhd 命令,底层还是 createmedium。

网络资源

「VirtualBox」- 挂载物理磁盘,并从物理磁盘启动 - K4NZ BLOG